﻿using SharpCommon;
using SharpWeb.Filter;
using SharpWeb.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;

namespace SharpWeb.Controllers
{
    public class HomeController : Controller
    {
        // GET: Home
        public ActionResult Index()
        {
            //SharpDB.DB db = new SharpDB.DB(SharpDB.AccessType.MsSql, System.Configuration.ConfigurationManager.ConnectionStrings["MsSql"].ConnectionString);
            return View();
        }

        [AjaxOnly]
        public ActionResult InitMenu()
        {
            return this.JsonSucesss(GetMenuHtml());
        }

        public string GetMenuHtml()
        {
            StringBuilder sbHtml = new StringBuilder();
            //所有顶部菜单
            var lstAllMenus = GetAllMenuTree();

            for (int j = 0; j < lstAllMenus.Count; j++)
            {
                var menu = lstAllMenus[j];
                sbHtml.AppendFormat("<li {0} >", menu.LIClassName);
                sbHtml.AppendFormat("<a href='javascript:;' {0} {1}>", menu.AClassName, menu.ADataToggle);
                sbHtml.AppendFormat("<i {0} />", menu.IClassName);
                sbHtml.AppendFormat("{0}{1}", menu.Title, menu.TitleNextHtml);
                sbHtml.AppendFormat("</a>");
                sbHtml.Append(menu.ANextHtml);//组装 下拉或树状 子菜单
                sbHtml.Append("</li>");
            }

            string topMenuHtml = sbHtml.ToString();
            return topMenuHtml;
        }

        /// <summary>
        /// 所有菜单
        /// </summary>
        /// <returns></returns>
        static  List<MenuItem> GetAllMenuTree()
        {
            var lstMenu = new List<MenuItem>()
            {
                //pid =-1 顶级菜单
                new MenuItem(title:"客户管理",isDefActive:1,id:"0"),
                new MenuItem(title:"内部办公",isContainsDropDownMenu:1,id:"1"),  

                new MenuItem(title:"联系人管理",id:"3"),
                new MenuItem(title:"产品管理"),
                new MenuItem(title:"售前管理"),
                new MenuItem(title:"销售管理"),
                new MenuItem(title:"服务管理"),
                new MenuItem(title:"合同管理"),
                new MenuItem(title:"财务管理"),
                new MenuItem(title:"人事管理"),
                new MenuItem(title:"项目管理")
            };
            return lstMenu;
        }

        public ActionResult MainIndex()
        {
            return View();
        }
    }
}